<?php
    require("messageLogic.Class.php");
    //$msgLogic = new messageLogic($strHost, $strUname, $strPasswd, $strDB);
    $msgLogic = new messageLogic("localhost", "root", "", "message");
    $arrMesgInfo = array();
    $arrMesgInfo['intRecvUid'] = 1;
    $arrMesgInfo['intSendUid'] = 2;
    $arrMesgInfo['strRecvUname'] = "Jingle";
    $arrMesgInfo['strSendUname'] = "Buffalo";
    $arrMesgInfo['intTypeId'] = 0;
    $arrMesgInfo['strMesgTitle'] = "this is message title.";
    $arrMesgInfo['strMesgContent'] = "this is message content.";
    $msgLogic->sendMessage($arrMesgInfo);
    $arrMesgList = $msgLogic->messageList(1, 0);
    assert(count($arrMesgList) == 1);
//    var_dump($arrMesgList);
    assert($arrMesgList[0]['send_user_id'] == $arrMesgInfo['intSendUid']);
    assert($arrMesgList[0]['send_user_name'] == $arrMesgInfo['strSendUname']);
    assert($arrMesgList[0]['mesg_title'] == $arrMesgInfo['strMesgTitle']);
    assert($arrMesgList[0]['hasread'] == 0);
    $arrcount = $msgLogic->messageCount($arrMesgInfo['intRecvUid']);
    assert($arrcount['friendmessage_all'] == 1);
    assert($arrcount['friendmessage_unread'] == 1);
    assert($arrcount['systemmessage_all'] == 0);
    assert($arrcount['systemmessage_unread'] == 0);
    assert($arrcount['friendinvite_all'] == 0);
    assert($arrcount['friendinvite_unread'] == 0);
    $arrcontent = $msgLogic->messageContent($arrMesgInfo['intRecvUid'], $arrMesgList[0]['mesg_id']);
//    var_dump($arrcontent);
    assert($arrcontent['send_user_id'] == $arrMesgInfo['intSendUid']);
    assert($arrcontent['send_user_name'] == $arrMesgInfo['strSendUname']);
    assert($arrcontent['type_id'] == $arrMesgInfo['intTypeId']);
    assert($arrcontent['mesg_title'] == $arrMesgInfo['strMesgTitle']);
    assert($arrcontent['mesg_content'] == $arrMesgInfo['strMesgContent']);
//    var_dump($arrMesgList);
    $msgLogic->setMessageReaded($arrMesgInfo['intRecvUid'], $arrMesgList[0]['mesg_id']);
    $arrcount = $msgLogic->messageCount($arrMesgInfo['intRecvUid']);
    assert($arrcount['friendmessage_all'] == 1);
    assert($arrcount['friendmessage_unread'] == 0);
    assert($arrcount['systemmessage_all'] == 0);
    assert($arrcount['systemmessage_unread'] == 0);
    assert($arrcount['friendinvite_all'] == 0);
    assert($arrcount['friendinvite_unread'] == 0);
    $msgLogic->deleteRecvMessage($arrMesgInfo['intRecvUid'], $arrMesgList[0]['mesg_id']);
    $arrcount = $msgLogic->messageCount($arrMesgInfo['intRecvUid']);
    assert($arrcount['friendmessage_all'] == 0);
    assert($arrcount['friendmessage_unread'] == 0);
    assert($arrcount['systemmessage_all'] == 0);
    assert($arrcount['systemmessage_unread'] == 0);
    assert($arrcount['friendinvite_all'] == 0);
    assert($arrcount['friendinvite_unread'] == 0);
    $msgLogic->deleteSendMessage($arrMesgInfo['intSendUid'], $arrMesgList[0]['mesg_id']);

    // 置顶测试
    $strTopMesgTitle = "this is topMesgTitle";
    $strTopMesgContent = "this is topMesgContent";
    $msgLogic->addTopMessage($strTopMesgTitle, $strTopMesgContent);
    $topMesgList = $msgLogic->messageTopList(2);
    assert(count($topMesgList) == 1);
    assert ($topMesgList[0]['top_mesg_title'] == $strTopMesgTitle );
    $arrTopMesgContent = $msgLogic->messageTopContent($topMesgList[0]['top_mesg_id']);
    assert ($arrTopMesgContent['top_mesg_content'] == $strTopMesgContent );
    assert ($arrTopMesgContent['insert_time'] == $topMesgList[0]['insert_time']);
    $msgLogic->delTopMessage($topMesgList[0]['top_mesg_id']);
?>
